﻿CREATE VIEW [dbo].[Top10PercentIndexesPerDatabase]
	AS SELECT    
			svr.Name AS Server, 
			svc.Name AS InstanceName, 
			db.DatabaseName,
			TTPI.TableName,
			TTPI.IndexName, 
			TTPI.IndexType, 
			IndexSize,							 
			[TTPI].Statistics_LastUpdatedDate,			
			TTPI.Fragmentation,
			db.DatabaseID,
			db.ServiceID
FROM         
                      [Database] AS db  INNER JOIN
                      Service AS svc ON db.ServiceID = svc.ServiceID INNER JOIN
                      Server AS svr ON svc.ServerID = svr.ServerID 
                      
                      CROSS APPLY
                      
                      dbo.Top10PercentIndexes(db.DatabaseID) AS TTPI   